import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import java.util.Set;

public class RedisDemoGeneric {
    public static void test1(Jedis jedis){
        System.out.println("get set");
        jedis.flushAll();
        jedis.set("key", "111");
        jedis.set("key2", "222");
        jedis.set("key3", "333");
        jedis.set("key4", "444");
        // boolean result = jedis.exists("key");
        // long result2 = jedis.del("key");
        // boolean result3 = jedis.exists("key");
        // System.out.println(result+" "+result2+" "+result3);
        // long result4 = jedis.del("key","key2","key3","key4");
        // boolean result2 = jedis.exists("key2");
        // System.out.println(result+" "+result2+" "+result4);
        Set<String> keys=jedis.keys("*");
        System.out.println(keys);

    }
    public static void test2(Jedis jedis)  {
        System.out.println("expire ttl");
        jedis.flushAll();
        jedis.set("key", "111");
        jedis.expire("key", 10);
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        long time = jedis.ttl("key");
        System.out.println(time);
    }

    public static void test3(Jedis jedis)  {
        System.out.println("type:");
        jedis.flushAll();
        jedis.set("key", "111");
        String type=jedis.type("key");
        System.out.println(type);
        jedis.lpush("key1", "111", "222", "333", "444");
        String type1=jedis.type("key1");
        System.out.println(type1);
        jedis.hset("key2", "f1", "111");
        String type2=jedis.type("key2");
        System.out.println(type2);
        jedis.sadd("key3","111","222","kzf");
        String type3=jedis.type("key3");
        System.out.println(type3);
        jedis.zadd("key4",10,"kzf");
        String type4=jedis.type("key4");
        System.out.println(type4);
    }
    public static void main(String[] args)  {
        JedisPool jedisPool = new JedisPool("tcp://127.0.0.1:8888");
        try (Jedis jedis = jedisPool.getResource()) {
            // String pong = jedis.ping();
            // System.out.println(pong);
            // test1(jedis);
            // test2(jedis);
            test3(jedis);
        }
    }
}
